package com.neusoft.chenhanhua.wh0913;

import javax.print.attribute.standard.MediaSize.JIS;

public class Calculator {
	private int x;
	private int y;
	private String mark;
	
	public Calculator(String diyi,String dier,String yunsfu,String zuih) {
		boolean ni=isNumeric(diyi);
		if (isCwu(yunsfu)) {
			this.mark=yunsfu;
		}
		if (ni) {
			this.x=Integer.parseInt(diyi);
			this.y=Integer.parseInt(dier);
		}
		if (zuih.equals("=")) {
			JIS();
			
		}else if(zuih.equals("q") && zuih.equals("Q")) {
			
			
		} else if(zuih.equals("c")){
             this.x=0;
             this.y=0;
             this.mark="";
		}
		
	}
	public Calculator() {
		
	}
   public Calculator(int x,int y,String mark) {
	   this.x=x;
	   this.y=y;
	   this.mark=mark;
		
	}
//   public int reture(String mark) {
//	   int result = 0;
//	   switch (mark) {
//	case "+":
//		result= x+y;
//		System.out.println(x+"+"+y+"="+result);
//		break;
//	case "-":
//		result= x-y;
//		System.out.println(x+"-"+y+"="+result);
//		break;
//	case "*":
//		result= x*y;
//		System.out.println(x+"*"+y+"="+result);
//		break;
//	case "/":
//		result= x/y;
//		System.out.println(x+"/"+y+"="+result);
//		break;
//
//	default:
//		break;
//	}
//	   return result;
//   }
	
	public int getX() {
		return x;
	}

	public void setX(int x) {
		this.x = x;
	}

	public int getY() {
		return y;
	}

	public void setY(int y) {
		this.y = y;
	}

	public String getMark() {
		return mark;
	}

	public void setMark(String mark) {
		this.mark = mark;
	}
	

	@Override
	public String toString() {
		return "Calculator [x=" + x + ", y=" + y + ", mark=" + mark + "]";
	}
	
     
	//判断字符串是否为纯数字的
    public  boolean isNumeric(String str){
        for(int i=0;i<str.length();i++){
            if(!Character.isDigit(str.charAt(i))){
                return false;
            }
        }
        return true;
    }
    public boolean isCwu(String q) {
    	if(q.equals("+") || q.equals("-") || q.equals("*") || q.equals("/")) {
    		return true;
    	}
    	return false;
    }
    public void JIS() {
    	if (mark.equals("+")) {
			System.out.println(x+"+"+y+"="+(x+y));
		} else if(mark.equals("-")) {
			System.out.println(x+"-"+y+"="+(x-y));
		}else if(mark.equals("/")) {
			System.out.println(x+"/"+y+"="+(x/y));
		}else if(mark.equals("*")) {
			if (y!=0) {
				System.out.println(x+"*"+y+"="+(x*y));
			}else {
				System.out.println(y+"为除数，不能为0");
			}
			
		}
    }

}
